package com.c8a.validation.controller;

import com.c8a.validation.entity.Student;
import com.c8a.validation.entity.Teacher;
import com.c8a.validation.service.TeacherService;
import com.c8a.validation.service.TeacherService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 校验二:在在实现层校验
 *
 * @Author C8A
 * @Date 2022-04-23 20:33
 * @Email 1912327276@qq.com
 */

@RestController
public class TeacherController {
    @Autowired
    TeacherService teacherService;
    @Autowired
    TeacherService1 teacherService1;

    /**
     * {
     * "id": 1,
     * "name": "c8a",
     * "password": "12345678",
     * "email": "42@qq.com",
     * "isValid": true,
     * "isInvalid": false,
     * "sort": 0,
     * "orderByAt": 1,
     * "startDate": "2020-11-30 00:00:00",
     * "endDate": "2025-11-30 00:00:00"
     * }
     *
     * @param teacher
     * @return
     */
    @PostMapping("/valid3")
    public ResponseEntity<Teacher> valid3(@Valid @RequestBody Teacher teacher) {
        Teacher teacher1 = teacherService.teacherService(teacher);
        return ResponseEntity.ok(teacher1);
    }

    @PostMapping("/valid4")
    public ResponseEntity<Teacher> valid4(@Valid @RequestBody Teacher teacher) {
        Teacher teacher2 = teacherService1.validTeacher(teacher);
        return ResponseEntity.ok(teacher2);
    }

    @PostMapping("/valid5")
    public ResponseEntity<Teacher> valid5(@RequestBody Teacher teacher) {
        Teacher build = Teacher.builder().id(teacher.getId()).name(teacher.getName()).password(teacher.getPassword()).isInvalid(teacher.getIsInvalid()).isValid(teacher.getIsValid()).email(teacher.getEmail()).build();
        Teacher teacher3 = teacherService1.validTeacher(build);
        return ResponseEntity.ok(teacher3);
    }
}
